package com.niit.bookmanage.controller;

import com.niit.bookmanage.domain.vo.BookBorrowCountVO;
import com.niit.bookmanage.domain.vo.BookDurationVO;
import com.niit.bookmanage.domain.vo.BookTypeVO;
import com.niit.bookmanage.domain.vo.BorrowVO;
import com.niit.bookmanage.service.BookBorrowCountService;
import com.niit.bookmanage.service.DataService;
import com.niit.bookmanage.service.SexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Liweijian.
 * @date 2024/6/7 18:47
 */

@RestController
@RequestMapping("/anlyze")
public class AnlyzeController {

    @Autowired
    private SexService sexService;

    @Autowired
    BookBorrowCountService bookBorrowCountService;

    @Autowired
    DataService dataService;
    @GetMapping("/sexCount")
    public List<BorrowVO> getSexCount() {
        List<BorrowVO> list = sexService.getSexCount();
        System.out.println(list);
        return list;
    }

    @GetMapping("/borrowCount")
    public List<BorrowVO> getBorrowCount(@RequestParam(required = false) String bookName) {
        System.out.println("书名"+ bookName);
        List<BorrowVO> list = bookBorrowCountService.getBorrowAndReturnCount(bookName);
        System.out.println(list);
        return list;
    }

    @GetMapping("/showBookNames")
    public List<String> getAllBookNames() {
        System.out.println(bookBorrowCountService.getAllBookNames());
        return bookBorrowCountService.getAllBookNames();
    }

    @GetMapping("/topFiveBooks")
    public List<BookBorrowCountVO> getTopFiveBooks() throws SQLException {
        List<BookBorrowCountVO> countVOList = bookBorrowCountService.getTopFiveBooks();
        System.out.println(countVOList);
        return countVOList;
    }

    @GetMapping("/topThreeTypes")
    public List<BookTypeVO> getTopThreeTypes() throws SQLException {
        List<BookTypeVO> bookTypeVOList = bookBorrowCountService.getTopThreeType();
        System.out.println(bookTypeVOList);
        return bookTypeVOList;
    }

    @GetMapping("/duration")
    public List<BookDurationVO> getDurations() {
        return dataService.getBookDuration();
    }
}

